﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_CodgDict : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainCodgConfigRule");

            migrationBuilder.DropTable(
                name: "MainMsgReadRec");

            migrationBuilder.DropTable(
                name: "MainSysMenuAclAbility");

            migrationBuilder.DropTable(
                name: "MainSysMenuAclRole");

            migrationBuilder.DropTable(
                name: "MainCodgConfig");

            migrationBuilder.DropTable(
                name: "MainMsgSendRec");

            migrationBuilder.DropTable(
                name: "MainSysMenu");

            migrationBuilder.DropTable(
                name: "MainMsgBizType");

            migrationBuilder.CreateTable(
                name: "MainCodgDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Code = table.Column<string>(type: "text", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCodgDict", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainEventMsgSendRec",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MsgBizTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    MsgName = table.Column<string>(type: "text", nullable: false),
                    MsgCont = table.Column<string>(type: "text", nullable: false),
                    MsgSendUserid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgSendUsername = table.Column<string>(type: "text", nullable: true),
                    MsgSendDeptid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgSendDeptname = table.Column<string>(type: "text", nullable: true),
                    MsgRecvDeptid = table.Column<string>(type: "text", nullable: true),
                    MsgRecvDeptname = table.Column<string>(type: "text", nullable: true),
                    MsgRecvUserid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgRecvUsername = table.Column<string>(type: "text", nullable: true),
                    MsgStats = table.Column<int>(type: "integer", nullable: false),
                    MsgLv = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainEventMsgSendRec", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainMenu",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MenuCode = table.Column<string>(type: "character varying(50)", maxLength: 50, nullable: false),
                    Text = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: false),
                    I18n = table.Column<string>(type: "character varying(48)", maxLength: 48, nullable: true),
                    Icon = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    GrpFlag = table.Column<bool>(type: "boolean", nullable: false),
                    HideInBreadcrumbFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Link = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    ClientId = table.Column<string>(type: "text", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMenu", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMenu_MainMenu_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainMenu",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "MainCodgDictRule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    CodgDictRuleType = table.Column<int>(type: "integer", nullable: false),
                    Format = table.Column<string>(type: "text", nullable: true),
                    DefaultValue = table.Column<string>(type: "text", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    CodgDictId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCodgDictRule", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainCodgDictRule_MainCodgDict_CodgDictId",
                        column: x => x.CodgDictId,
                        principalTable: "MainCodgDict",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "MainMenuAclAbility",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    Ability = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMenuAclAbility", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMenuAclAbility_MainMenu_MenuId",
                        column: x => x.MenuId,
                        principalTable: "MainMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainMenuAclRole",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    RoleCode = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMenuAclRole", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMenuAclRole_MainMenu_MenuId",
                        column: x => x.MenuId,
                        principalTable: "MainMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainCodgDictRule_CodgDictId",
                table: "MainCodgDictRule",
                column: "CodgDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainMenu_MenuCode",
                table: "MainMenu",
                column: "MenuCode");

            migrationBuilder.CreateIndex(
                name: "IX_MainMenu_ParentId",
                table: "MainMenu",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_MainMenuAclAbility_MenuId",
                table: "MainMenuAclAbility",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_MainMenuAclRole_MenuId",
                table: "MainMenuAclRole",
                column: "MenuId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainCodgDictRule");

            migrationBuilder.DropTable(
                name: "MainEventMsgSendRec");

            migrationBuilder.DropTable(
                name: "MainMenuAclAbility");

            migrationBuilder.DropTable(
                name: "MainMenuAclRole");

            migrationBuilder.DropTable(
                name: "MainCodgDict");

            migrationBuilder.DropTable(
                name: "MainMenu");

            migrationBuilder.CreateTable(
                name: "MainCodgConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Codg = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCodgConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainMsgBizType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    MsgBizTypeCodg = table.Column<string>(type: "text", nullable: false),
                    MsgBizTypeName = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMsgBizType", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainSysMenu",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    ClientId = table.Column<string>(type: "text", nullable: true),
                    GrpFlag = table.Column<bool>(type: "boolean", nullable: false),
                    HideInBreadcrumbFlag = table.Column<bool>(type: "boolean", nullable: false),
                    I18n = table.Column<string>(type: "character varying(48)", maxLength: 48, nullable: true),
                    Icon = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    LeafFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Link = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
                    MenuCode = table.Column<string>(type: "text", nullable: false),
                    RootFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Text = table.Column<string>(type: "character varying(48)", maxLength: 48, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainSysMenu", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainSysMenu_MainSysMenu_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainSysMenu",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "MainCodgConfigRule",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    CodgConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    DefaultValue = table.Column<string>(type: "text", nullable: true),
                    Format = table.Column<string>(type: "text", nullable: false),
                    Len = table.Column<int>(type: "integer", nullable: false),
                    NoDictRuleType = table.Column<int>(type: "integer", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainCodgConfigRule", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainCodgConfigRule_MainCodgConfig_CodgConfigId",
                        column: x => x.CodgConfigId,
                        principalTable: "MainCodgConfig",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "MainMsgSendRec",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MsgBizTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "character varying(40)", maxLength: 40, nullable: false),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgCont = table.Column<string>(type: "text", nullable: false),
                    MsgLv = table.Column<int>(type: "integer", nullable: false),
                    MsgName = table.Column<string>(type: "text", nullable: false),
                    MsgRecvDeptid = table.Column<string>(type: "text", nullable: true),
                    MsgRecvDeptname = table.Column<string>(type: "text", nullable: true),
                    MsgRecvUserid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgRecvUsername = table.Column<string>(type: "text", nullable: true),
                    MsgSendDeptid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgSendDeptname = table.Column<string>(type: "text", nullable: true),
                    MsgSendUserid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgSendUsername = table.Column<string>(type: "text", nullable: true),
                    MsgStats = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMsgSendRec", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMsgSendRec_MainMsgBizType_MsgBizTypeId",
                        column: x => x.MsgBizTypeId,
                        principalTable: "MainMsgBizType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainSysMenuAclAbility",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    SysMenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    ABILITY = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainSysMenuAclAbility", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainSysMenuAclAbility_MainSysMenu_SysMenuId",
                        column: x => x.SysMenuId,
                        principalTable: "MainSysMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainSysMenuAclRole",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    SysMenuId = table.Column<Guid>(type: "uuid", nullable: false),
                    ROLE_CODE = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainSysMenuAclRole", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainSysMenuAclRole_MainSysMenu_SysMenuId",
                        column: x => x.SysMenuId,
                        principalTable: "MainSysMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainMsgReadRec",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    MsgSendRecId = table.Column<Guid>(type: "uuid", nullable: false),
                    MsgRecvTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    MsgRecvUserid = table.Column<Guid>(type: "uuid", nullable: true),
                    MsgRecvUsername = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainMsgReadRec", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainMsgReadRec_MainMsgSendRec_MsgSendRecId",
                        column: x => x.MsgSendRecId,
                        principalTable: "MainMsgSendRec",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainCodgConfigRule_CodgConfigId",
                table: "MainCodgConfigRule",
                column: "CodgConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainMsgReadRec_MsgSendRecId",
                table: "MainMsgReadRec",
                column: "MsgSendRecId");

            migrationBuilder.CreateIndex(
                name: "IX_MainMsgSendRec_MsgBizTypeId",
                table: "MainMsgSendRec",
                column: "MsgBizTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_MainSysMenu_MenuCode",
                table: "MainSysMenu",
                column: "MenuCode");

            migrationBuilder.CreateIndex(
                name: "IX_MainSysMenu_ParentId",
                table: "MainSysMenu",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_MainSysMenuAclAbility_SysMenuId",
                table: "MainSysMenuAclAbility",
                column: "SysMenuId");

            migrationBuilder.CreateIndex(
                name: "IX_MainSysMenuAclRole_SysMenuId",
                table: "MainSysMenuAclRole",
                column: "SysMenuId");
        }
    }
}
